package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConst;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Permission;
import com.itheima.service.PermissionService;
import com.sun.javafx.logging.PulseLogger;
import com.sun.scenario.animation.AnimationPulseMBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author leboy
 * @description
 */
@RestController
@RequestMapping("permission")
@Slf4j
public class PermissionController {

	@Reference
	private PermissionService permissionService;

	/**
	 *  权限管理的分页查询
	 */
	@RequestMapping("findByPage")
	public Result findByPage(@RequestBody QueryPageBean queryPageBean){
		log.debug("进入分页权限查询****************queryPageBean:"+queryPageBean);
		PageResult pageResult = permissionService.findByPage(queryPageBean);
		log.debug("查询结果：pageResult是"+pageResult);
		return new Result(true, MessageConst.QUERY_PERMISSION_SUCCESS, pageResult);
	}

	@RequestMapping("add")
	public Result add(@RequestBody  Permission permission){
		log.debug("进入添加权限页面**************permission:"+permission);
		permissionService.add(permission);
		return new Result(true,MessageConst.ADD_PERMISSION_SUCCESS);
	}

	@RequestMapping("delById")
	public Result delById(Integer id){
		log.debug("进入根据id删除，id为:"+id);
		permissionService.delById(id);
		return new Result(true,MessageConst.DELETE_PERMISSION_SUCCESS);
	}

	@RequestMapping("findById")
	public Result findById(Integer id){
		log.debug("findById****************参数id:"+id);
		Permission permission =  permissionService.findById(id);
		return new Result(true,MessageConst.QUERY_PERMISSION_SUCCESS,permission);
	}

	@RequestMapping("edit")
	public Result edit(@RequestBody Permission permission){
		log.debug("编辑权限************permission:"+permission);
		permissionService.edit(permission);
		return new Result(true,MessageConst.EDIT_PERMISSION_SUCCESS);
	}
}
